package com.yiwyn;

import com.yiwyn.reflectdemo.domain.Animal;
import com.yiwyn.reflectdemo.domain.Cat;
import com.yiwyn.reflectdemo.event.TestEvent;

import java.lang.reflect.Field;

public class Main {


    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {

        // Animal dog = new Animal();
        // Animal cat = new Animal();
        //
        // Field dogNameField = dog.getClass().getDeclaredField("name");
        // Field catNameField = cat.getClass().getDeclaredField("name");
        //
        // System.out.println(dogNameField.equals(catNameField));


        Cat cat = new Cat();
        cat.setName("tomcat");
        cat.setAge(2);


        Field testEvent = cat.getClass().getDeclaredField("testEvent");
        testEvent.setAccessible(true);
        System.out.println(TestEvent.class.isAssignableFrom(testEvent.getType()));
        TestEvent o = (TestEvent) testEvent.get(cat);
        o.trigger(cat);


    }


}